import 'package:flutter/material.dart';
import 'package:jd_flutter/base/foundation/flutter_extension.dart';
import 'package:jd_flutter/base/foundation/jd_colors.dart';
import 'package:jd_flutter/base/net/jd_request.dart';
import 'package:jd_flutter/base/widget/basic/base_list_widget.dart';
import 'package:jd_flutter/base/widget/basic/jd_app_bar.dart';
import 'package:jd_flutter/modules/config/url_constant.dart';
import 'package:jd_flutter/modules/pages/question/models/question_model.dart';
import 'package:jd_flutter/modules/pages/question/widgets/question_cell.dart';

class QuestionPage extends StatefulWidget {
  const QuestionPage({super.key});

  @override
  State<QuestionPage> createState() => _QuestionPageState();
}

class _QuestionPageState
    extends CommonListWidgetState<QuestionItem, QuestionPage> {
  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: JDColors.backgroundColor,
      appBar: JDAppBar(
        title: '问题',
        showBackButton: false,
      ),
      body: super.build(context),
    );
  }

  @override
  JDApiRequest get apiUrlRequest => JDApiRequest.get(JDNetworkUrl.questionList);

  @override
  Widget createItemWidget(BuildContext context, QuestionItem data, int index) {
    return QuestionCell(item: data);
  }

  @override
  List<QuestionItem> parsingData(
      bool isDownRequest, Map<String, dynamic> response) {
    List listMap = response.getItemsListNotNull();
    return listMap.map((e) {
      return QuestionItem.fromJson(e);
    }).toList();
  }
}
